package main

import (
	"encoding/json"
	"fmt"
)

type Monster struct {
	Name     string  `json:"name"`
	Age      int     `json:"age"`
	Birthday string  `json:"birthday"`
	Salary   float64 `json:"salary"`
	Skill    string  `json:"skill"`
}

func test() {
	monster := Monster{
		Name:     "牛魔王",
		Age:      500,
		Birthday: "1500",
		Salary:   50000,
		Skill:    "牛魔拳",
	}
	data, err := json.Marshal(&monster)
	if err != nil {
		fmt.Println("序列化失败")
	}
	fmt.Println(string(data))
}
func testMapSerial() {
	var a map[string]interface{}
	a = make(map[string]interface{}, 10)
	a["name"] = "泰隆"
	a["age"] = 30
	a["skill"] = [2]string{"斩草除根", "诺克萨斯式外交"}
	a["address"] = "召唤师峡谷"

	data, err := json.Marshal(a)
	if err != nil {
		fmt.Println("序列化失败")
	}
	fmt.Println(string(data))
}
func testSlice() {
	var slice []map[string]interface{}
	var s1 map[string]interface{}
	s1 = make(map[string]interface{})
	s1["name"] = "vn"
	s1["skill"] = [...]string{"终极时刻", "闪避突袭", "无情猎手"}
	var s2 map[string]interface{}
	s2 = make(map[string]interface{})
	s2["name"] = "jinx"
	s2["skill"] = []string{"枪炮交响曲", "暴走快感"}
	var s3 map[string]interface{}
	s3 = make(map[string]interface{})
	s3["name"] = "riven"
	s3["skill"] = "折翼之舞"
	slice = append(slice, s1, s2, s3)
	data, err := json.Marshal(slice)
	if err != nil {
		fmt.Println("序列化失败")
	}
	fmt.Println(string(data))
}
func main() {
	testSlice()
}
